﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.CodeRush.StructuralParser;

namespace DX_SourceOutliner
{
    public class ReturnTypeNameAppenderProcessor : INodeProcessor
    {

        IEnumerable<LanguageElementType> _typesApprovedToProcess;

        /// <summary>
        /// Initializes a new instance of the ReturnTypeNameAppenderProcessor class.
        /// </summary>
        public ReturnTypeNameAppenderProcessor()
        {
            _typesApprovedToProcess = new List<LanguageElementType>()
            {
                LanguageElementType.Method, 
                LanguageElementType.Variable, 
                LanguageElementType.InitializedVariable, 
                LanguageElementType.Const, 
                LanguageElementType.Property, 
                LanguageElementType.Delegate, 
                LanguageElementType.Event
            };
        }


        ISourceTreeNode _source;
        TreeNode _node;

        public TreeNode Process(TreeNode node)
        {
            _node = node;
            _source = _node.Tag as ISourceTreeNode;

            if (_source.Element != null && _typesApprovedToProcess.Contains(_source.Element.ElementType))
                AppendTypeDeclaration();

            return _node;
        }


        private void AppendTypeDeclaration()
        {
            string typeDeclaration = _source.TypeDeclarationText;

            if (!string.IsNullOrEmpty(typeDeclaration))
                _node.Text = string.Format("{0} : {1}", _node.Text, typeDeclaration);
        }

    }
}
